package com.univrz.flexmachine.scmxml
{
	
	
	import com.univrz.flexmachine.core.Node;
	import com.univrz.flexmachine.events.StateMachineEvent;
	import com.univrz.flexmachine.scmxml.i.ITransition;
	
	
/**
 *  
 * 
 *  @eventType com.univrz.flexmachine.events.StateMachineEvent.FIRE
 */
[Event(name="fire", type="com.univrz.flexmachine.events.StateMachineEvent")]		

	
	public class Transition extends Node implements ITransition
	{
		

		
		

		////////////////////////////////////////////////////////
		//  target 
		////////////////////////////////////////////////////////

		private var _target:*;
		
		/**
		 * 
		 * @param v
		 * 
		 */		
		public function set target( v:* ):void
		{
			if ( _target == v )
			{
				return;
			}
			_target = v;
			
			
			// v can be a string
			// (v as Object).registerIncomingTransition( this );
			
		}
		
		public function get target( ):*
		{
			return _target;
		}


		
		

		////////////////////////////////////////////////////////
		//  resolvedTargets 
		////////////////////////////////////////////////////////		
		
		public static function get resolvedTargets( ):Array
		{
			
			return null;
		}
		
		
		
		

		///////////////////////////////////////////////////////
		// event
		///////////////////////////////////////////////////////
		
		/**
		 * 
		 * Can be
		 * 
		 * - Trigger
		 * - [ IEventDispatcher, eventType:String ]
		 * - eventType:String
		 * 
		 */		

		private var _event:*;
		public function get event( ):*
		{
			return _event;
		}
		public function set event( v:* ):void
		{
			if ( _event == v )
				return;
			
			_event = v;			
		}
		
		
		
		
		///////////////////////////////////////////////////////
		// cond
		///////////////////////////////////////////////////////		

		private var _cond:Boolean = true;
		public function get cond( ):Boolean
		{
			return _cond;
		}
		public function set cond( v:Boolean ):void
		{
			if ( _cond == v )
				return;
			
			_cond = v;
			
			dispatchEvent( new StateMachineEvent( StateMachineEvent.COND_CHANGED ) );
			dispatchEvent( new StateMachineEvent( StateMachineEvent.IS_ENABLED_CHANGED ) );
		}
		



		///////////////////////////////////////////////////////
		// isEnabled
		///////////////////////////////////////////////////////	
		
		private var _isEnabled:Boolean = true;
		[Bindable("isEnabledChanged")]
		public function get isEnabled():Boolean
		{
			if ( ! cond )
				return false;
				
			// if ( ! ( _source as Object ).isActive ) return false;
			
			return true;
		}
	
	
	
		private function source_isActiveChanged( event:StateMachineEvent ):void
		{
			dispatchEvent( new StateMachineEvent( StateMachineEvent.IS_ENABLED_CHANGED ) );
		}
	
			
		
		////////////////////////////////////////////////
		// firing
		////////////////////////////////////////////////

		internal function fire( ):void
		{
			if ( isEnabled )
			{
				// StateMachineInternalUtil.doTransition( target, midTransitionCallback );			
			}
		}
		
		
		
		private function midTransitionCallback():void
		{
			dispatchEvent( new StateMachineEvent( StateMachineEvent.FIRE ) );		
		}		
		
		
		
		
		





		////////////////////////////////////////////////////////////////////////////////////////////////
		// 
		////////////////////////////////////////////////////////////////////////////////////////////////




		

























		
		
		
		




	}
}